/*
 * @(#) SecureBaseAction.java  1.0  2004-3-15
 *
 * Copyright 2003 by LongTop Corporation.
 * 2669 XieTu Road, ShangHai, PRC 200030
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * LongTop Corporation ("Confidential Information").  You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with LongTop.
 */

package com.cnc.bas.web;

import com.cnc.bas.util.Constants;
import com.cnc.ssm.UserInfo;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author Du bf
 * @version 1.0  2004-3-15
 */
public abstract class SecureBaseAction extends BasAction {

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        UserInfo acctForm = (UserInfo) request.getSession().getAttribute(Constants.USER_KEY);
        if (acctForm == null) {
            String url = request.getServletPath();
            String query = request.getQueryString();
            if (query != null) {
                request.setAttribute("signonForwardAction", url + "?" + query);
            } else {
                request.setAttribute("signonForwardAction", url);
            }
            return mapping.findForward("logon");
        } else {
            return doExecute(mapping, form, request, response);
        }
    }

    protected abstract ActionForward doExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception;

}